unit Class_BILL;


interface
uses
  Classes,SysUtils,DB,Uni,UniEngine;

type
  TBILL=class(TUniEngine)
  private
    FBILLID   : Integer;
    FBILLCODE : string;
    FBILLTYPE : string;
    FBILLBANK : string;
    FBILLTITLE: string;
    FBILLDATE : TDateTime;
    FBILLACCEPTMAN: string;
    FBILLPAYACCOUNT: string;
    FBILLPAYBANK: string;
    FBILLPAYMAN: string;
    FBILLMONEY: Extended;
    FBILLUSES : string;
    FBILLPAYPSWD: string;
    FBILLADDTION: string;
    FBILLUNITMANAGE: string;
    FBILLACCOUNT: string;
    FBILLACCEPTBANK: string;
    FBILLACCEPTACCOUNT: string;
    FBILLPAYOUTADD: string;
    FBILLACCEPTINADD: string;
    FBILLCONTENT: string;
    FBILLSTAT : Integer;
    FEXPDTYPE : string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    //#function  GetNextIndx:Integer;overload;
    //#function  GetNextIndx(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property BILLID   : Integer read FBILLID    write FBILLID;
    property BILLCODE : string read FBILLCODE  write FBILLCODE;
    property BILLTYPE : string read FBILLTYPE  write FBILLTYPE;
    property BILLBANK : string read FBILLBANK  write FBILLBANK;
    property BILLTITLE: string read FBILLTITLE write FBILLTITLE;
    property BILLDATE : TDateTime read FBILLDATE  write FBILLDATE;
    property BILLACCEPTMAN: string read FBILLACCEPTMAN write FBILLACCEPTMAN;
    property BILLPAYACCOUNT: string read FBILLPAYACCOUNT write FBILLPAYACCOUNT;
    property BILLPAYBANK: string read FBILLPAYBANK write FBILLPAYBANK;
    property BILLPAYMAN: string read FBILLPAYMAN write FBILLPAYMAN;
    property BILLMONEY: Extended read FBILLMONEY write FBILLMONEY;
    property BILLUSES : string read FBILLUSES  write FBILLUSES;
    property BILLPAYPSWD: string read FBILLPAYPSWD write FBILLPAYPSWD;
    property BILLADDTION: string read FBILLADDTION write FBILLADDTION;
    property BILLUNITMANAGE: string read FBILLUNITMANAGE write FBILLUNITMANAGE;
    property BILLACCOUNT: string read FBILLACCOUNT write FBILLACCOUNT;
    property BILLACCEPTBANK: string read FBILLACCEPTBANK write FBILLACCEPTBANK;
    property BILLACCEPTACCOUNT: string read FBILLACCEPTACCOUNT write FBILLACCEPTACCOUNT;
    property BILLPAYOUTADD: string read FBILLPAYOUTADD write FBILLPAYOUTADD;
    property BILLACCEPTINADD: string read FBILLACCEPTINADD write FBILLACCEPTINADD;
    property BILLCONTENT: string read FBILLCONTENT write FBILLCONTENT;
    property BILLSTAT : Integer read FBILLSTAT  write FBILLSTAT;
    property EXPDTYPE : string read FEXPDTYPE  write FEXPDTYPE;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(aBILL:TBILL):TBILL;overload;        
    class procedure CopyIt(aBILL:TBILL;var Result:TBILL);overload;       
  end;

implementation

{ TBILL }
procedure TBILL.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('BILL_ID').Value := BILLID;
        ParamByName('BILL_CODE').Value := BILLCODE;
        ParamByName('BILL_TYPE').Value := BILLTYPE;
        ParamByName('BILL_BANK').Value := BILLBANK;
        ParamByName('BILL_TITLE').Value := BILLTITLE;
        ParamByName('BILL_DATE').Value := BILLDATE;
        ParamByName('BILL_ACCEPTMAN').Value := BILLACCEPTMAN;
        ParamByName('BILL_PAYACCOUNT').Value := BILLPAYACCOUNT;
        ParamByName('BILL_PAYBANK').Value := BILLPAYBANK;
        ParamByName('BILL_PAYMAN').Value := BILLPAYMAN;
        ParamByName('BILL_MONEY').Value := BILLMONEY;
        ParamByName('BILL_USES').Value := BILLUSES;
        ParamByName('BILL_PAYPSWD').Value := BILLPAYPSWD;
        ParamByName('BILL_ADDTION').Value := BILLADDTION;
        ParamByName('BILL_UNITMANAGE').Value := BILLUNITMANAGE;
        ParamByName('BILL_ACCOUNT').Value := BILLACCOUNT;
        ParamByName('BILL_ACCEPTBANK').Value := BILLACCEPTBANK;
        ParamByName('BILL_ACCEPTACCOUNT').Value := BILLACCEPTACCOUNT;
        ParamByName('BILL_PAYOUTADD').Value := BILLPAYOUTADD;
        ParamByName('BILL_ACCEPTINADD').Value := BILLACCEPTINADD;
        ParamByName('BILL_CONTENT').Value := BILLCONTENT;
        ParamByName('BILL_STAT').Value := BILLSTAT;
        ParamByName('EXPD_TYPE').Value := EXPDTYPE; 
      end;
      otEdit:
      begin
        ParamByName('BILL_ID').Value := BILLID;
        ParamByName('BILL_CODE').Value := BILLCODE;
        ParamByName('BILL_TYPE').Value := BILLTYPE;
        ParamByName('BILL_BANK').Value := BILLBANK;
        ParamByName('BILL_TITLE').Value := BILLTITLE;
        ParamByName('BILL_DATE').Value := BILLDATE;
        ParamByName('BILL_ACCEPTMAN').Value := BILLACCEPTMAN;
        ParamByName('BILL_PAYACCOUNT').Value := BILLPAYACCOUNT;
        ParamByName('BILL_PAYBANK').Value := BILLPAYBANK;
        ParamByName('BILL_PAYMAN').Value := BILLPAYMAN;
        ParamByName('BILL_MONEY').Value := BILLMONEY;
        ParamByName('BILL_USES').Value := BILLUSES;
        ParamByName('BILL_PAYPSWD').Value := BILLPAYPSWD;
        ParamByName('BILL_ADDTION').Value := BILLADDTION;
        ParamByName('BILL_UNITMANAGE').Value := BILLUNITMANAGE;
        ParamByName('BILL_ACCOUNT').Value := BILLACCOUNT;
        ParamByName('BILL_ACCEPTBANK').Value := BILLACCEPTBANK;
        ParamByName('BILL_ACCEPTACCOUNT').Value := BILLACCEPTACCOUNT;
        ParamByName('BILL_PAYOUTADD').Value := BILLPAYOUTADD;
        ParamByName('BILL_ACCEPTINADD').Value := BILLACCEPTINADD;
        ParamByName('BILL_CONTENT').Value := BILLCONTENT;
        ParamByName('BILL_STAT').Value := BILLSTAT;
        ParamByName('EXPD_TYPE').Value := EXPDTYPE; 
      end;  
      otDelt:
      begin
        ParamByName('BILL_ID').Value := BILLID;
 
      end;  
    end;
  end;
end;

function TBILL.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result := CheckExist('TBL_BILL',['BILL_ID',BILLID],AUniConnection);
end;

function TBILL.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_BILL WHERE   BILL_ID=:BILL_ID';
end;

function TBILL.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_BILL'
         +'    ( BILL_ID, BILL_CODE, BILL_TYPE, BILL_BANK, BILL_TITLE'
         +'    , BILL_DATE, BILL_ACCEPTMAN, BILL_PAYACCOUNT, BILL_PAYBANK'
         +'    , BILL_PAYMAN, BILL_MONEY, BILL_USES, BILL_PAYPSWD, BILL_ADDTION'
         +'    , BILL_UNITMANAGE, BILL_ACCOUNT, BILL_ACCEPTBANK, BILL_ACCEPTACCOUNT'
         +'    , BILL_PAYOUTADD, BILL_ACCEPTINADD, BILL_CONTENT, BILL_STAT'
         +'    , EXPD_TYPE)'
         +'    VALUES'
         +'    (:BILL_ID,:BILL_CODE,:BILL_TYPE,:BILL_BANK,:BILL_TITLE'
         +'    ,:BILL_DATE,:BILL_ACCEPTMAN,:BILL_PAYACCOUNT,:BILL_PAYBANK'
         +'    ,:BILL_PAYMAN,:BILL_MONEY,:BILL_USES,:BILL_PAYPSWD,:BILL_ADDTION'
         +'    ,:BILL_UNITMANAGE,:BILL_ACCOUNT,:BILL_ACCEPTBANK,:BILL_ACCEPTACCOUNT'
         +'    ,:BILL_PAYOUTADD,:BILL_ACCEPTINADD,:BILL_CONTENT,:BILL_STAT'
         +'    ,:EXPD_TYPE)';
end;

function TBILL.GetStrsIndex: string;
begin
  Result:=Format('%D',[BILLID]);
end;

function TBILL.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_BILL SET'
         +'    BILL_CODE=:BILL_CODE,'
         +'    BILL_TYPE=:BILL_TYPE,'
         +'    BILL_BANK=:BILL_BANK,'
         +'    BILL_TITLE=:BILL_TITLE,'
         +'    BILL_DATE=:BILL_DATE,'
         +'    BILL_ACCEPTMAN=:BILL_ACCEPTMAN,'
         +'    BILL_PAYACCOUNT=:BILL_PAYACCOUNT,'
         +'    BILL_PAYBANK=:BILL_PAYBANK,'
         +'    BILL_PAYMAN=:BILL_PAYMAN,'
         +'    BILL_MONEY=:BILL_MONEY,'
         +'    BILL_USES=:BILL_USES,'
         +'    BILL_PAYPSWD=:BILL_PAYPSWD,'
         +'    BILL_ADDTION=:BILL_ADDTION,'
         +'    BILL_UNITMANAGE=:BILL_UNITMANAGE,'
         +'    BILL_ACCOUNT=:BILL_ACCOUNT,'
         +'    BILL_ACCEPTBANK=:BILL_ACCEPTBANK,'
         +'    BILL_ACCEPTACCOUNT=:BILL_ACCEPTACCOUNT,'
         +'    BILL_PAYOUTADD=:BILL_PAYOUTADD,'
         +'    BILL_ACCEPTINADD=:BILL_ACCEPTINADD,'
         +'    BILL_CONTENT=:BILL_CONTENT,'
         +'    BILL_STAT=:BILL_STAT,'
         +'    EXPD_TYPE=:EXPD_TYPE'
         +'    WHERE BILL_ID=:BILL_ID';
end;

constructor TBILL.Create;
begin

end;

destructor TBILL.Destroy;
begin

  inherited;
end;

class function TBILL.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result := TBILL.Create;
  TBILL.ReadDS(AUniQuery,Result);
end;

class procedure TBILL.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  if Result = nil then Exit;

  with TBILL(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=UpperCase(Field.FieldName);
      if FieldName='BILL_ID' then
      begin
        BILLID    := Field.AsInteger;
      end else
      if FieldName='BILL_CODE' then
      begin
        BILLCODE  := Field.AsString;
      end else
      if FieldName='BILL_TYPE' then
      begin
        BILLTYPE  := Field.AsString;
      end else
      if FieldName='BILL_BANK' then
      begin
        BILLBANK  := Field.AsString;
      end else
      if FieldName='BILL_TITLE' then
      begin
        BILLTITLE := Field.AsString;
      end else
      if FieldName='BILL_DATE' then
      begin
        BILLDATE  := Field.AsDateTime;
      end else
      if FieldName='BILL_ACCEPTMAN' then
      begin
        BILLACCEPTMAN := Field.AsString;
      end else
      if FieldName='BILL_PAYACCOUNT' then
      begin
        BILLPAYACCOUNT := Field.AsString;
      end else
      if FieldName='BILL_PAYBANK' then
      begin
        BILLPAYBANK := Field.AsString;
      end else
      if FieldName='BILL_PAYMAN' then
      begin
        BILLPAYMAN := Field.AsString;
      end else
      if FieldName='BILL_MONEY' then
      begin
        BILLMONEY := Field.AsFloat;
      end else
      if FieldName='BILL_USES' then
      begin
        BILLUSES  := Field.AsString;
      end else
      if FieldName='BILL_PAYPSWD' then
      begin
        BILLPAYPSWD := Field.AsString;
      end else
      if FieldName='BILL_ADDTION' then
      begin
        BILLADDTION := Field.AsString;
      end else
      if FieldName='BILL_UNITMANAGE' then
      begin
        BILLUNITMANAGE := Field.AsString;
      end else
      if FieldName='BILL_ACCOUNT' then
      begin
        BILLACCOUNT := Field.AsString;
      end else
      if FieldName='BILL_ACCEPTBANK' then
      begin
        BILLACCEPTBANK := Field.AsString;
      end else
      if FieldName='BILL_ACCEPTACCOUNT' then
      begin
        BILLACCEPTACCOUNT := Field.AsString;
      end else
      if FieldName='BILL_PAYOUTADD' then
      begin
        BILLPAYOUTADD := Field.AsString;
      end else
      if FieldName='BILL_ACCEPTINADD' then
      begin
        BILLACCEPTINADD := Field.AsString;
      end else
      if FieldName='BILL_CONTENT' then
      begin
        BILLCONTENT := Field.AsString;
      end else
      if FieldName='BILL_STAT' then
      begin
        BILLSTAT  := Field.AsInteger;
      end else
      if FieldName='EXPD_TYPE' then
      begin
        EXPDTYPE  := Field.AsString;
      end;
    end
  end;  
end;

class function  TBILL.CopyIt(aBILL: TBILL): TBILL;
begin
  Result := TBILL.Create;
  TBILL.CopyIt(aBILL,Result)
end;

class procedure TBILL.CopyIt(aBILL:TBILL;var Result:TBILL);
begin
  if Result = nil then Exit;
  Result.BILLID   := aBILL.BILLID;
  Result.BILLCODE := aBILL.BILLCODE;
  Result.BILLTYPE := aBILL.BILLTYPE;
  Result.BILLBANK := aBILL.BILLBANK;
  Result.BILLTITLE:= aBILL.BILLTITLE;
  Result.BILLDATE := aBILL.BILLDATE;
  Result.BILLACCEPTMAN:= aBILL.BILLACCEPTMAN;
  Result.BILLPAYACCOUNT:= aBILL.BILLPAYACCOUNT;
  Result.BILLPAYBANK:= aBILL.BILLPAYBANK;
  Result.BILLPAYMAN:= aBILL.BILLPAYMAN;
  Result.BILLMONEY:= aBILL.BILLMONEY;
  Result.BILLUSES := aBILL.BILLUSES;
  Result.BILLPAYPSWD:= aBILL.BILLPAYPSWD;
  Result.BILLADDTION:= aBILL.BILLADDTION;
  Result.BILLUNITMANAGE:= aBILL.BILLUNITMANAGE;
  Result.BILLACCOUNT:= aBILL.BILLACCOUNT;
  Result.BILLACCEPTBANK:= aBILL.BILLACCEPTBANK;
  Result.BILLACCEPTACCOUNT:= aBILL.BILLACCEPTACCOUNT;
  Result.BILLPAYOUTADD:= aBILL.BILLPAYOUTADD;
  Result.BILLACCEPTINADD:= aBILL.BILLACCEPTINADD;
  Result.BILLCONTENT:= aBILL.BILLCONTENT;
  Result.BILLSTAT := aBILL.BILLSTAT;
  Result.EXPDTYPE := aBILL.EXPDTYPE;
end;

end.

